package com.baiyang.server.service.transaction.impl;


import com.baiyang.server.model.transaction.Orders;
import com.baiyang.server.service.impl.BaseServiceImpl;
import com.baiyang.server.service.transaction.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service;

import com.baiyang.server.dao.transaction.LogisticsDao;
import com.baiyang.server.model.transaction.Logistics;
import com.baiyang.server.service.transaction.LogisticsService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 
 * @author XVX
 * BY: @Primary 注解帮助生命@Autowired优先注入的实列
 */
@Service	
public class LogisticsServiceImpl extends BaseServiceImpl<LogisticsDao, Logistics> implements LogisticsService{
    @Autowired
    private LogisticsDao logisticsDao = null;
    @Autowired
    private OrdersService ordersService = null;

    @Override
    public Logistics getNewByOrderId(String id) {
        return logisticsDao.getNewByOrderId(id);
    }

    @Transactional
    @Override
    public void insertLogistics(Logistics logistics) {
        logisticsDao.insert(logistics);
        // 修改订单状态
        Orders orders = new Orders();
        orders.setId(logistics.getOrderId());
        orders = ordersService.selectOne(orders);
        if("0".equals(orders.getState())){
            orders.setState("1");
            ordersService.updateById(orders);
        }
    }
}
